<include file="Public/header" />
<include file="Public/menu" />

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            采购
            <small>我的采购单</small>
        </h1>

    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="row"><div class="col-md-12"><div class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                <li <if condition="I('get.view') eq 0" >class="active"</if> ><a href="{:U(orders/orderList,array('view'=>0))}">待确认</a></li>
                <li <if condition="I('get.view') eq 1" >class="active"</if> ><a href="{:U(orders/orderList,array('view'=>1))}">处理中</a></li>
                <li <if condition="I('get.view') eq 2" >class="active"</if> ><a href="{:U(orders/orderList,array('view'=>2))}">已完成</a></li>
                <li <if condition="I('get.view') eq 3" >class="active"</if> ><a href="{:U(orders/orderList,array('view'=>3))}">已取消</a></li>
                <li <if condition="I('get.view') eq 4" >class="active"</if> ><a href="{:U(orders/orderList,array('view'=>4))}">全部</a></li>
                <li class="pull-right header"></li>
            </ul>
            <div class="tab-content">
                <div class="box-header">
                    <h3 class="box-title"></h3>


                    <!--<div class="form-inline pull-right">
                        <form action="{:U('purchase/shoppingList',array('view'=>$view,'order_field'=>$order_field,'order'=>$order), '')}" method="get" pjax-container="">
                            <fieldset>
                                <div class="input-group input-group-sm">
                                    <span class="input-group-addon"><strong>店铺名称</strong></span>
                                    <input type="hidden" name="search_field" value="local_name">
                                    <input type="text" class="form-control" placeholder="搜索" name="search" value="{$search}">
                                </div>
                                <div class="input-group input-group-sm">
                                    <div class="input-group-btn">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i></button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>-->
                </div>

                <div class="tab-pane active" id="tab_0">
                    <div class="box">

                        <!-- /.box-header -->
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover" style="width: 100%;">
                                <tbody><tr>
                                    <!--<th><input type="checkbox" class="grid-select-all"></th>-->
                                    <th>ID<a class="fa fa-fw fa-sort" href="{:U('purchase/shoppingList',array('view'=>$view,'p'=>$p,'order_field'=>'purc_id','order'=>$order), '')}"></a></th>
                                    <th>采购总价格<a class="fa fa-fw fa-sort" href="{:U('purchase/shoppingList',array('view'=>$view,'p'=>$p,'order_field'=>'purc_price','order'=>$order), '')}"></a></th>
                                    <if condition="I('view') eq 4">
                                        <th>状态<a class="fa fa-fw fa-sort" href="{:U('purchase/shoppingList',array('view'=>$view,'p'=>$p,'order_field'=>'status','order'=>$order), '')}"></a></th>
                                    </if>
                                    <th>备注</th>
                                    <th>更新时间<a class="fa fa-fw fa-sort" href="{:U('purchase/shoppingList',array('view'=>$view,'p'=>$p,'order_field'=>'last_modify','order'=>$order), '')}"></a></th>
                                    <th>创建时间<a class="fa fa-fw fa-sort" href="{:U('purchase/shoppingList',array('view'=>$view,'p'=>$p,'order_field'=>'uptime','order'=>$order), '')}"></a></th>
                                    <th>操作</th>
                                </tr>
                                <volist name="list" id="item">
                                    <tr>
                                        <!--<td><input type="checkbox" class="grid-item" data-id="{$item.purc_id}"></td>-->
                                        <td>{$item.purc_id}</td>
                                        <td>￥{$item.purc_price}</td>
                                        <if condition="I('view') eq 4">
                                            <switch name="item.status">
                                                <case value="0"><td><span class="badge bg-blue">待确认</span></td></case>
                                                <case value="1"><td><span class="badge bg-orange">处理中</span></td></case>
                                                <case value="2"><td><span class="badge bg-green">已完成</span></td></case>
                                                <case value="3"><td><span class="badge bg-danger">已取消</span></td></case>
                                            </switch>
                                        </if>
                                        <td>{$item.remark}</td>
                                        <td>{$item.last_modify|date="Y-m-d H:i",###}</td>
                                        <td>{$item.uptime|date="Y-m-d H:i",###}</td>
                                        <td>
                                            <a href="{:U('purchase/products', array('purc_id'=>$item['purc_id']))}" class="btn btn-sm btn-primary">查看</a>
                                            <if condition="$item.status eq 0">
                                                <a data-id="{$item.purc_id}" before="{$item.status}" status="3" class="btn btn-sm btn-danger grid-refreshe __confirm">取消</a>
                                                <elseif condition="$item.status eq 1"/>
                                                <a data-id="{$item.purc_id}" before="{$item.status}" status="3" class="btn btn-sm btn-danger grid-refreshe __confirm">取消</a>
                                                <a data-id="{$item.purc_id}" class="btn btn-sm btn-success grid-refreshe _logs">查看日志</a>
                                                <else />
                                                <a data-id="{$item.purc_id}" class="btn btn-sm btn-success grid-refreshe _logs">查看日志</a>
                                            </if>
                                        </td>
                                    </tr>
                                </volist>
                                </tbody></table>
                        </div>
                        <div class="box-footer clearfix">
                            <!--<input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;-->
                            <!--<a class="btn btn-sm btn-danger batch-delete">批量删除</a>-->

                            <a class="btn btn-sm btn-primary grid-refresh"><i class="fa fa-refresh"></i></a>

                            {$page}

                        </div>
                        <!-- /.box-body -->
                    </div>

                    <!-- 模态框（Modal） -->
                    <div class="modal fade" id="myModallogs" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">
                                        订单状态变更日志
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    暂无记录
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        关闭
                                    </button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
                         aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"
                                            aria-hidden="true">×
                                    </button>
                                    <h4 class="modal-title" id="myModalLabel">
                                        订单状态变更
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    <form action="" role="form" id="purchase-mark">
                                        <div class="form-group">
                                            <input type="hidden" name="purc_id" value="">
                                            <input type="hidden" name="status" value="">
                                            <input type="hidden" name="status" value="">
                                            <label for="exampleInputEmailbz">备注</label>
                                            <textarea class="form-control" rows="2" id="exampleInputEmailbz" placeholder="添加备注" name="desc"></textarea>
                                        </div>
                                    </form>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">
                                        关闭
                                    </button>
                                    <button type="button" class="btn btn-primary  mark-submit">
                                        提交
                                    </button>
                                </div>
                            </div><!-- /.modal-content -->
                        </div><!-- /.modal-dialog -->
                    </div><!-- /.modal -->

                </div>

                <div class="tab-pane " id="tab_{$k}">
                    <div class="box">
                        <div class="box-body table-responsive no-padding">
                            {$table}
                        </div>
                    </div>
                </div>


            </div>
        </div></div></div>

    </section>
</div>
<!-- 底部 -->
<include file="Public/common_footer" />

<script data-exec-on-popstate>
    $(function () {
        $('.mark-submit').click(function () {

            var purc_id = $('#purchase-mark').find('input[name=purc_id]').val();
            var status = $('#purchase-mark').find('input[name=status]').val();
            var before = $('#purchase-mark').find('input[name=before]').val();
            var desc = $('#purchase-mark').find('textarea[name=desc]').val();
            if (purc_id != '' && status != '' && desc != '') {
                $.ajax({
                    type: "POST",
                    url: "{:U('purchase/change_status')}",
                    data: {purc_id:purc_id, status:status, desc:desc, before:before},
                    success: function(msg){
                        $('#myModal').modal('hide');
                        if (msg.status) {
                            alert(msg.message);
                        } else {
                            alert(msg.message)
                        }
                        window.location.reload();
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        });

        $('.__confirm').click(function () {
            $('#myModal').modal('show');
            var purc_id = $(this).attr('data-id');
            var before = $(this).attr('before');
            var status = $(this).attr('status');
            $('#purchase-mark').find('input[name=purc_id]').val(purc_id);
            $('#purchase-mark').find('input[name=before]').val(before);
            $('#purchase-mark').find('input[name=status]').val(status);
        });

        $('._logs').click(function () {
            //$('#myModallogs').modal('show');
            var purc_id = $(this).attr('data-id');
            if (purc_id != '') {
                $.ajax({
                    type: "get",
                    url: "{:U('purchase/get_purchase_logs')}",
                    data: {purc_id:purc_id},
                    success: function(msg){
                        $('#myModallogs').modal('show');
                        var html='';
                        if (msg) {
                            for (var i=0; i<msg.length; i++) {
                                html += '<p class="message"><a class="name"> <small class="text-muted pull-right"><i class="fa fa-clock-o"></i>';
                                html += msg[i].create_time + '</small>';
                                html += msg[i].manage_name + '</a>&nbsp;&nbsp;&nbsp;&nbsp;将状态变更为：<a>';
                                html += msg[i].later_status+'</a><br><label class="control-label">备注内容：</label>';
                                html += msg[i].desc + '</p>';
                            }
                        }
                        $('#myModallogs').find('.modal-body').html(html);
                    },
                    error: function (msg) {
                        alert(msg.message);
                    }
                });
            } else {
                alert('缺少参数');
            }
        });


    })
</script>